import java.io.Console;


//I'm loshara, misunderstood the task
public class Stamp {
	public int getMinimumCost(String desiredColor, int stampCost, int pushCost) {
		int min = Integer.MAX_VALUE;
		int n = desiredColor.length();
		
		char[] color = new char[]{'R','G','B'};
		
		outer: for (int l = 1; l<=n; l++) {
			char[] cc = new char[n];
			for (int i=0; i<n; i++) cc[i] = desiredColor.charAt(i);
			
			int used = 0;
			int filled = 0;			
			while (filled < n) {
				int max = 0, bestpos = -1;
				for (int i=0; i+l<=n; i++) {										
					cycle: for (int col = 0; col < 3; col++) {						
						int m = 0;
						for (int j=i; j<l+i; j++) {
							if (cc[j] == '*' || cc[j] == color[col]) {
								m++;
							} else if (cc[j] == 'F') {
								
							} else continue cycle;
						}
						if (m > max) {
							max = m;
							bestpos = i;
						}
					}														
				}
				
				if (bestpos == -1) continue outer;
				filled += max;
				for (int j=0; j<l; j++) {
					cc[j+bestpos] = 'F';
				}
				used += 1;
			}
			
			int r = used*pushCost + l*stampCost;
			if (r < min) min = r;
		}
		
		return min;
	}
	
	public static void main(String[] args) {
		System.out.println(new Stamp().getMinimumCost("BRRB", 2, 7));
	}
}
